<?php

namespace app\controller;
use app\BaseController;
use think\facade\Db;
use think\facade\Request;

class Jsbundle extends BaseController {
    // config.headers.model = model;
    //     config.headers.bundleID = bundleID;
    //     config.headers.systemVersion = systemVersion;
    //     config.headers.appVersion = appVersion;
    //     config.headers.appBuildNumber = appBuildNumber;
    //     config.headers.language = language;
    //     config.headers.deviceID = deviceID;
    //     config.headers.zone = zone;
    //     config.headers.brand = brand
    //     config.headers.os = Platform.OS == 'ios' ? 1 : 2
    public function index() {
        $bundle_id = Request::header("bundleID");
        $appVersion = Request::header("appVersion");
        $jsVersion = Request::header("jsVersion");
        $os = Request::header("os");
        $jsBundle = Db::name("js_bundle_record")
                        ->where("bundle_id",$bundle_id)
                        ->where("app_version",$appVersion)
                        ->where("platform",$os)
                        ->find();
        if (!$jsBundle) {
            # code...
            return json([
                'code' => 400,
                'msg' => "record not found"
            ]);
        }
        $record_js_version = $jsBundle["js_version"];
        return json([
                'code' => 200,
                'msg' => "get success",
                "data"=>[
                    "url"=>$jsBundle["zip_url"],
                    "md5"=>$jsBundle["md5"],
                    "jsVersion"=>$record_js_version,
                ]
            ]);
    }
}